//
//  EpointCacheDB.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-2-14.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "EpointCacheDB.h"

@implementation EpointCacheDB

-(id)init
{
    self = [super init];
    if (self) {
        sqlite3_open([[EpointCacheDB getDBFilePath] UTF8String],&database);
        [self createTable:"create table if not exists framecache(key text,value text)"];
        [self createTable:"create table if not exists webinfocache(InfoGuid text,txtTitle text,Content text,PostUserName text,PostDate text,InfoProperty text,IsRead text,HasAttach text,FeedBackCount text)"];
    }
    return self;
}

//建表操作
-(void)createTable:(char *)sql
{
    char *errorMsg;
    sqlite3_exec(database, sql, NULL, NULL, &errorMsg);
    if (errorMsg!=NULL) {
        NSLog(@"ERR:%s",errorMsg);
    }
}

+(NSString *)getDBFilePath
{
    NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *dbFilePath = [[documentsPaths objectAtIndex:0]stringByAppendingPathComponent:@"EpointCacheDB"];
    return dbFilePath;
}

-(sqlite3*)getCacheDB
{
    return database;
}

@end
